<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
          <div style="margin: 0px 2px;">
            <el-button
                type="danger"
                class="filter-item"
                size="mini"
                icon="el-icon-refresh"
                @click="refresh"
              >刷新</el-button>
          </div>
    
     </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
  
      <!--表单组件-->
      <epick2 ref="formDetail" :is-add="isAdd" />
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" title="砍价详情" width="1000px">


        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
       
          <el-form-item label="用户参与砍价表ID">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户ID">
            <el-input v-model="form.uid" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="砍价产品id">
            <el-input v-model="form.bargainId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="砍价的最低价">
            <el-input v-model="form.bargainPriceMin" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="砍价金额">
            <el-input v-model="form.bargainPrice" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="砍掉的价格">
            <el-input v-model="form.price" style="width: 370px;" />
          </el-form-item>

          <!--
          <el-form-item label="状态 1参与中 2 活动结束参与失败 3活动结束参与成功" prop="status">
            <el-input v-model="form.status" style="width: 370px;" />
          -->

          
          </el-form-item>
          <el-form-item label="参与时间">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="updateTime">
            <el-input v-model="form.updateTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否取消" prop="isDel">
            <el-input v-model="form.isDel" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <!--
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
          -->
          
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
          <el-table-column
            label="序号"
            type="index"
            width="50"
            align="center">
          </el-table-column>
          <el-table-column prop="uid" label="发起人" width="150" >
            <template slot-scope="scope">
              头像：<a :href="scope.row.user.avatar" style="color: #42b983" target="_blank"><img :src="scope.row.user.avatar" alt="点击打开" class="el-avatar"></a><br>
              昵称：{{ scope.row.user.nickname }}<br>
              用户ID：{{ scope.row.user.uid }}<br>
              手机号：{{ scope.row.user.phone }}
            </template>
          </el-table-column>
          <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="发起时间">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="砍价产品"width="200">
            <template slot-scope="scope">
              产品主图：<a :href="scope.row.yxStoreBargain.image" style="color: #42b983" target="_blank"><img :src="scope.row.yxStoreBargain.image" alt="点击打开" class="el-avatar"></a><br>
              砍价名称：{{ scope.row.yxStoreBargain.title }}<br>
              砍价 ID：{{ scope.row.yxStoreBargain.id }}
            </template>
          </el-table-column>

          <el-table-column prop="uid" label="砍价库存"  >
            <template slot-scope="scope">
              {{ scope.row.product.attrInfo.bargain_stock }}
            </template>
          </el-table-column>
          <el-table-column prop="uid" label="砍价标价"  >
            <template slot-scope="scope">
              {{ scope.row.product.attrInfo.bargain_price }}
            </template>
          </el-table-column>
          <el-table-column prop="uid" label="砍成价"  >
            <template slot-scope="scope">
              {{ scope.row.product.attrInfo.bargain_ok_price }}
            </template>
          </el-table-column>

          <el-table-column prop="uid" label="砍掉的价格"  >
            <template slot-scope="scope">
              {{ scope.row.price }}
            </template>
          </el-table-column>

          <el-table-column prop="uid" label="帮砍人数"  >
            <template slot-scope="scope">
              {{ scope.row.cutCount }}
            </template>
          </el-table-column>
      

        <el-table-column label="砍价状态">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 1">进行中</span>
            <span v-else-if="scope.row.status == 2">砍价失败</span>
            <span v-else-if="scope.row.status == 3">砍价成功</span>
            <span v-else>其他</span>
          </template>
        </el-table-column>
       
      
        <el-table-column v-permission="['admin','yxStoreBargainUser:edit','yxStoreBargainUser:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">

          <!--
          <udOperation
              :data="scope.row"
              :permission="permission"
            >
            
            </udOperation>
          -->
          
            <el-button
                      v-if="scope.row.status == 2 || scope.row.status == 3"
                      v-permission="['admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT']"
                      size="mini"
                      type="primary"
                      @click="detail(scope.row)"
            >
            帮砍详情</el-button>

          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudYxStoreBargainUser from '@/api/yxStoreBargainUser'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import epick2 from './form'
import MaterialList from "@/components/material";

// crud交由presenter持有
const defaultCrud = CRUD({ title: 'YxBargainUser', url: 'api/yxStoreBargainUser', sort: 'id,desc', crudMethod: { ...crudYxStoreBargainUser }})
const defaultForm = { id: null, uid: null, bargainId: null, bargainPriceMin: null, bargainPrice: null, price: null, status: null, createTime: null, updateTime: null, isDel: null }
export default {
  name: 'YxStoreBargainUser',
  components: { pagination, crudOperation,epick2, rrOperation, udOperation ,MaterialList},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['user_status'],
  data() {
    return {

      permission: {
        add: ['admin', 'yxStoreBargainUser:add'],
        edit: ['admin', 'yxStoreBargainUser:edit'],
        del: ['admin', 'yxStoreBargainUser:del']
      },
      rules: {
        status: [
          { required: true, message: '状态 1参与中 2 活动结束参与失败 3活动结束参与成功不能为空', trigger: 'blur' }
        ],
        isDel: [
          { required: true, message: '是否取消不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'status', display_name: '状态 1参与中 2 活动结束参与失败 3活动结束参与成功' }
      ]
    }
  },
  watch: {
  },
  methods: {
   detail(data) {
        this.isAdd = false
        const _this = this.$refs.formDetail
        _this.form = data;
        _this.dialog = true
    },
    refresh(){
      this.crud.toQuery();
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }else{
        delete this.crud.params.status
      }
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
      console.log(form)
    },
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
